//
//  StatusRetweetedView.m
//  王雷Sinoweibo
//
//  Created by wanglei on 16/11/25.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "StatusRetweetedView.h"

@implementation StatusRetweetedView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    self.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    [self setupUi];
    return self;
}

- (void)setupUi{
    UILabel *label = [[UIlabel_extension alloc]initWithtext:@"转发微博,终于等到你" fontsize:14 textColor:[UIColor darkGrayColor] Alignment:NSTextAlignmentLeft];
    _retweetedLabel = label;
    StatusPictureView *PictureView = [[StatusPictureView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    _pictureView = PictureView;
    
    [self addSubview:_retweetedLabel];
    [self addSubview:_pictureView];
    
    [_retweetedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).offset(StatusCellMargin);
        make.right.equalTo(self.mas_right).offset(-StatusCellMargin);
    }];
    
    [_pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_retweetedLabel.mas_bottom).offset(StatusCellMargin);
        make.left.equalTo(_retweetedLabel.mas_left);
    }];
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        self.bottomConstaint = make.bottom.equalTo(_pictureView.mas_bottom).offset(StatusCellMargin);
    }];
    
}

-(void)setRetweetedStatus:(Status *)retweetedStatus{
    _retweetedLabel.text = retweetedStatus.text;
    [self.bottomConstaint uninstall];
    if ((retweetedStatus.imageURLs != nil)&&(retweetedStatus.imageURLs.count != 0)) {
        _pictureView.imageURLs = retweetedStatus.imageURLs;
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            self.bottomConstaint = make.bottom.equalTo(_pictureView.mas_bottom).offset(StatusCellMargin);
        }];
        _pictureView.hidden = false;
    }else{
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            self.bottomConstaint = make.bottom.equalTo(_retweetedLabel.mas_bottom).offset(StatusCellMargin);
        }];
        _pictureView.hidden = true;
    }
    
}
@end
